#ifndef _UBT_STATE_API_H_
#define _UBT_STATE_API_H_
#include <string>
#include <vector>
#include "ubt_state/ubt_state_config.h"

namespace ubt_state
{
/*状态描述*/
#define UBT_STATE_CLOSE_STR "UBT_CLOSE"
#define UBT_STATE_INITIAL_STR "UBT_INIT"
#define UBT_STATE_INITPOSE_STR "UBT_INITPOSE"
#define UBT_STATE_WAIT_STR "UBT_WAIT"
#define UBT_STATE_MAPPING_STR "UBT_MAPPING"
#define UBT_STATE_RUN_STR "UBT_RUN"
#define UBT_STATE_ACTION_STR "UBT_ACTION"
#define UBT_STATE_RECHARGE_STR "UBT_RECHARGE"
#define UBT_STATE_CHARGE_STR "UBT_CHARGE"
#define UBT_STATE_OBSTACLE_STR "UBT_OBSTACLE"
#define UBT_STATE_PAUSE_STR "UBT_PAUSE"
#define UBT_STATE_STOP_STR "UBT_STOP"
#define UBT_STATE_REFAULT_STR "UBT_REFAULT"
#define UBT_STATE_NREFAULT_STR "UBT_NREFAULT"
#define UBT_STATE_RMCTL_STR "UBT_RMCTL"
#define UBT_STATE_CHARGEMANUL_STR "UBT_CHARGEMANUAL"
#define UBT_STATE_PAUSEMANUL_STR "UBT_PAUSEMANUAL"
#define UBT_STATE_WAITPOSE_STR "UBT_WAITPOSE"
#define UBT_STATE_BREAKOPENED_STR "UBT_BREAKOPENED"
#define UBT_STATE_COLLIDE_STR "UBT_COLLIDE"
#define UBT_STATE_LIFTUP_STR "UBT_LIFTUP"
#define UBT_STATE_DRAGUP_STR "UBT_DRAGUP"
#define UBT_STATE_PAUSELIMIT_STR "UBT_PAUSELIMIT"
#define UBT_STATE_AUTOFIND_STR "UBT_AUTOFIND"
#define UBT_STATE_UPDATE_STR "UBT_UPDATE"
#define UBT_STATE_SHELFUP_STR "UBT_SHELFUP"
#define UBT_STATE_STANDALONE_MODE_STR "UBT_STANDALONE"



/*任务事件*/
#define UBT_TASK_EVENT_PROCESS_STR "TASK_PROCESS"	//开始
#define UBT_TASK_EVENT_ARRIVED_STR "TASK_ARRIVED"	//到达目标点
#define UBT_TASK_EVENT_FINISH_STR    "TASK_FINISH"	//正常完成

#define UBT_TASK_EVENT_SYS_ANTC_STR "SYS_ANTC"	//防撞条
#define UBT_TASK_EVENT_USR_STOPBTN_STR "USR_STOPBTN"	//急停按钮
#define UBT_TASK_EVENT_USR_BRAKEBTN_STR "USR_BRAKEBTN"	//解抱闸按钮
#define UBT_TASK_EVENT_SYS_POWEROFF_STR "SYS_POWEROFF"	//关机
#define UBT_TASK_EVENT_SYS_NRFAULT_STR "SYS_NRFAULT"	//不可恢复故障
#define UBT_TASK_EVENT_SYS_CHARGE_STR "SYS_CHARGE"	//充电

#define UBT_TASK_EVENT_SYS_BADSTATUS_STR "SYS_BADSTATUS"//状态不符
#define UBT_TASK_EVENT_SYS_POSEFAIL_STR "SYS_POSEFAIL"	//定位丢失
#define UBT_TASK_EVENT_MOD_TIMEOUT_STR "MOD_TIMEOUT"	// 超时

#define UBT_TASK_EVENT_REQ_BADPARAM_STR "REQ_BADPARAM"	//参数不对
#define UBT_TASK_EVENT_SYS_MAPUPDATE_STR "SYS_MAPUPDATE"	//地图更新
#define UBT_TASK_EVENT_USR_CANCEL_STR "USR_CANCEL"	//取消
#define UBT_TASK_EVENT_USR_DISPATCHCANCEL_STR "USR_DISPATCHCANCEL"	//调度取消
#define UBT_TASK_EVENT_NAVIGATION_CANCEL "NAVIGATION_CANCEL" // 取消导航

#define UBT_TASK_EVENT_NAV_ABORT_STR "NAV_ABORT"   //导航失败
#define UBT_TASK_EVENT_NAV_ABORTE3M_STR "NAV_ABORT_EXCEED_3M" //导航起点超过3米失败
#define UBT_TASK_EVENT_NAV_POSEJUMP_STR "NAV_POSEJUMP" //导航位置跳变
#define UBT_TASK_EVENT_NAV_TRACKFAIL_STR "NAV_TRACKFAIL" //导航跟踪轨迹失败
#define UBT_TASK_EVENT_ADJUST_ABORT_STR "ADJUST_ABORT" //调整失败
#define UBT_TASK_EVENT_CHARGE_ABORT_STR "CHARGE_ABORT" //上桩失败

#define UBT_ACTION_ADJUST_CODE "visual_servo" //二维码精定位
#define UBT_ACTION_MOVE_FORWARD "move_forward" //前进
#define UBT_ACTION_ROTATE       "rotate"             //旋转
#define UBT_ACTION_ROTATE_SYNC  "rotate_sync"      //车转货架不转
#define UBT_ACTION_RISE "rise" //顶升上升
#define UBT_ACTION_FALL "fall" //顶升下降
#define UBT_ACTION_GRAG_LIFT "drag_lift" //牵引销
#define UBT_ACTION_ONLINE_CHARGE "online_charge"//在线充电
#define UBT_ACTION_FORK_MEASURE "fork_measure"
#define UBT_ACTION_FORK_MEASURE_HEIGHT "fork_measure_height"
#define UBT_ACTION_FROK_TO_STATION "fork_to_station"

constexpr double DEFAULT_GOOD_WIDTH = 1.25;
constexpr double DEFAULT_GOOD_LENGTH = 1.25;
constexpr double DEFAULT_GOOD_HEIGHT = 1.75;
constexpr double DEFAULT_GOOD_LEG_LENGTH = 0.10;
constexpr double DEFAULT_GOOD_LEG_WIDTH = 0.08;
constexpr double DEFAULT_GOOD_BOTTOM_HEIGHT = 0.20;

struct Point
{
    float x;
    float y;
    float t;
    std::int32_t id;
    float avoidDis;//避障距离,0不避障,<0 无效值(保持不变)
    std::string rfid;
    std::string name;
    int direction_index;
    float x_vel;	//给到导航的x轴线速度,米/秒。
    float w_vel;	//给到导航的旋转速度,弧度/秒。
};

struct Limit
{
    float x;   //空载x轴线速度,米/秒
    float w;   //空载旋转速度,弧度/秒
    float lx;   //负载x轴线速度，米/秒
    float lw;   //负载旋转速度,弧度/秒
};

struct Line
{
    std::string type;//线段类型 line或 bezier
    std::vector<Point> points;
    Limit limit;	//速度限制
    float warning;	//报警距离
    float slow;		//减速距离
    float stop;		//急停距离
    float side;     //侧面避障距离
};

struct Action
{
    std::string  type;//动作类型
    std::string  value;//值
};

// 货架信息 shelf info
struct MapGood
{
    int id = -1;
    double width = DEFAULT_GOOD_WIDTH;  //货架宽度
    double length = DEFAULT_GOOD_LENGTH; //货架长度
    double height = DEFAULT_GOOD_HEIGHT; //货架高度
    std::string createTime;
    std::string goodType;
    double legLength = DEFAULT_GOOD_LEG_LENGTH;      //货架腿长度
    double legWidth = DEFAULT_GOOD_LEG_WIDTH;       //货架腿宽度
    double bottomHeight = DEFAULT_GOOD_BOTTOM_HEIGHT;   //货架底部高度
};

struct FixePathTaskInfo
{
    std::string taskId;
    std::string props;//UBT_TASK_PROP_xxx
    std::vector<Line> path;
#ifdef AVOID_CAR_SUPPORT
    int waitTime; //等待时间
#endif
    std::vector<Action> actions;
    MapGood mapGood;    // 货架信息 shelf info
};
#define UBT_TASK_PROP_STATION_POINT "station-point"
#define UBT_TASK_PROP_CHARGE_POINT "charge-point"
#define UBT_TASK_PROP_SHELF_POINT "shelves-point"

#ifdef AVOID_CAR_SUPPORT
    #define UBT_TASK_PROP_WAIT_POINT "wait-point"
#endif

/*
注：
1. 取消等待 (mission_action_wait_cancel) 与取消子任务 (mission_action_cancel) 时为 FINISHED；
2. 取消任务 (mission_cancel)，调度取消重规划路径 (dispatch_cancel)，为 WARNING
*/
#define UBT_TASK_STATUS_INPROCESS_STR  	"IN_PROCESS" //进行中
#define UBT_TASK_STATUS_ARRIVED_STR    	"ARRIVED" //已到达
#define UBT_TASK_STATUS_FINISH_STR   	"FINISHED"	//正常完成
#define UBT_TASK_STATUS_ERROR_STR    	"ERROR"	//异常完成
#define UBT_TASK_STATUS_WARNING_STR    	"WARNING"	//正常完成
int _ParsePointsFromJson(std::string infoStr, std::vector<Point> *points, std::string& failMsg);

int ParseFixedPathTaskInfo(std::string taskInfoStr, FixePathTaskInfo *pFixedPathTaskInfo, std::string& failMsg);
struct NavTaskLimitIndex
{
    std::string taskId;
    int waitLineIndex;
    int waitPointId;
    int cmd; //0:pause 1:continue
};
int ParseTaskLimitIndex(std::string taskLimitIndexStr, NavTaskLimitIndex *pTaskLimitIndex, std::string& failMsg);


std::string GetTaskEventByReason(int stopReason);

struct ApiTaskStatus
{
    std::string taskId;
    std::string status;//UBT_TASK_STATUS_xxx
    std::string desc;
    int actionIndex;
    std::string actionType;
};
std::string EncodeTaskStatus(ApiTaskStatus taskStatus);

struct ApiCode
{
    int state;
    long tag;
    float x;
    float y;
    float theta;
};

struct ApiModStatus
{
    long stamp;
    std::string state;
    ApiCode hw_UpCode;
    int  hw_LiftState;
};

std::string EncodeApiModStatus(ApiModStatus apiModStatus);

}
#endif /*_UBT_STATE_API_H_*/


